/**
 * @file main.cpp
 * @brief 节点属性插值程序的主入口
 */

#ifdef _WIN32
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#endif

#include <iostream>
#include <chrono>
#include "MeshProcessor.h"

/**
 * @brief 程序入口函数
 * @param argc 命令行参数数量
 * @param argv 命令行参数数组
 * @return 成功返回0，失败返回1
 * @throw std::runtime_error 当文件操作或插值计算失败时抛出异常
 * 
 * 执行流程:
 * 1. 设置K近邻搜索参数
 * 2. 读取已知节点和未知节点数据
 * 3. 执行插值计算
 * 4. 保存计算结果
 */
int main(int argc, char *argv[])
{
    try
    {
        #ifdef _WIN32
        SetConsoleOutputCP(CP_UTF8);
        #endif

        const size_t k_nearest = 20;
        MeshProcessor::setKNearestPoints(k_nearest);

        std::string current_dir = ".";
        std::string known_nodes_file = current_dir + "/q2/input/Grid_and_data.txt";
        std::string unknown_nodes_file = current_dir + "/q2/input/Result_grid_coordinates.txt";
        std::string output_file = current_dir + "/q2/output/output_Q2.txt";

        MeshProcessor processor(known_nodes_file,
                              unknown_nodes_file,
                              output_file);
        processor.process();

        return 0;
    }
    catch (const std::exception &e)
    {
        return 1;
    }
} 